<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('服务类型选择')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-service-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">服务类型选择：</label>
            <div class="col-sm-8">
                <select name="type" th:with="type=${@dict.getType('service_type')}" style="width: 150px;height: 30px;">
                    <option value="0">清选择服务类型</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}" th:hidden="${dict.dictValue<'5'?true:false}"></option>
                </select>
            </div>
        </div>
        <div id="urlService" style="display: none">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">服务名称：</label>
                <div class="col-sm-8">
                    <textarea id="name" rows="3" name="name" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">URL：</label>
                <div class="col-sm-8">
                    <textarea id="url" rows="4" name="url" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">描述：</label>
                <div class="col-sm-8">
                    <textarea id="description" rows="4" name="description" class="form-control" required></textarea>
                </div>
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "urlService";
    $(function () {
        $("select[name='type']").change(function () {
            var value = $("select[name='type']").val();
            if (value == '0') {
                $("#urlService").hide();
            }else{
                $("#urlService").show();
            }
        });
    })
    $("#form-service-add").validate({
        onkeyup: false,
        rules:{
            name:{
                maxlength: 1000,
            },
            url:{
                maxlength: 1000,
            },
            description:{
                maxlength: 1000,
            },
        },
        messages: {
            "name": {
                remote: "名称最长不超过1000字符"
            },
            "url": {
                remote: "名称最长不超过1000字符"
            },
            "description": {
                remote: "名称最长不超过1000字符"
            },
        },
        focusCleanup: true
    });
    function submitHandler() {
        if ($("select[name='type']").val() == '0') {
            $.modal.alert("请选择服务类型")
            return;
        }
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-service-add').serialize());
        }
    }
</script>
</body>
</html>
